<script setup>
import { ref, computed, onMounted, onUnmounted } from 'vue'

const companies = ref([
  { id: 1, name: '成都某科技有限公司', reason: '恶意欠款', time: '2024-03-15', punishment: '限制高消费', severity: 'high' },
  { id: 2, name: '重庆某系统有限公司', reason: '合同诈骗', time: '2024-03-14', punishment: '限制融资', severity: 'medium' },
  { id: 3, name: '杭州某网络有限公司', reason: '虚假宣传', time: '2024-03-13', punishment: '行业禁入', severity: 'low' },
  { id: 4, name: '南京某软件有限公司', reason: '拖欠工资', time: '2024-03-12', punishment: '信用降级', severity: 'medium' },
  { id: 5, name: '天津某电子有限公司', reason: '偷税漏税', time: '2024-03-11', punishment: '罚款处理', severity: 'high' }
])

const isLoading = ref(false)
const scrollRef = ref(null)
let scrollTimer

// 计算显示数据（用于无缝滚动）
const displayCompanies = computed(() => {
  return [...companies.value, ...companies.value]
})

// 自动滚动
const startScroll = () => {
  if (!scrollRef.value) return
  
  const scrollHeight = scrollRef.value.scrollHeight / 2
  let currentScroll = 0
  
  scrollTimer = window.setInterval(() => {
    currentScroll += 1
    if (currentScroll >= scrollHeight) {
      currentScroll = 0
      if (scrollRef.value) {
        scrollRef.value.scrollTop = 0
      }
    }
    if (scrollRef.value) {
      scrollRef.value.scrollTop = currentScroll
    }
  }, 50)
}

// 刷新数据
const refreshData = async () => {
  isLoading.value = true
  await new Promise(resolve => setTimeout(resolve, 1000)) // 模拟加载
  isLoading.value = false
}

// 添加鼠标事件处理
const handleMouseEnter = () => {
  if (scrollTimer) {
    clearInterval(scrollTimer)
  }
}

const handleMouseLeave = () => {
  startScroll()
}

onMounted(() => {
  startScroll()
  if (scrollRef.value) {
    scrollRef.value.addEventListener('mouseenter', handleMouseEnter)
    scrollRef.value.addEventListener('mouseleave', handleMouseLeave)
  }
})

onUnmounted(() => {
  if (scrollTimer) {
    clearInterval(scrollTimer)
  }
  if (scrollRef.value) {
    scrollRef.value.removeEventListener('mouseenter', handleMouseEnter)
    scrollRef.value.removeEventListener('mouseleave', handleMouseLeave)
  }
})
</script>

<template>
  <div class="panel-card blacklist">
    <div class="panel-header">
      <div class="header-title">
        <i class="fas fa-ban warning-icon pulse"></i>
        失信黑名单
        <span class="total-count">
          <i class="fas fa-building"></i>
          {{ companies.length }} 家企业
        </span>
      </div>
      <div class="header-actions">
        <button class="refresh-btn" @click="refreshData" :class="{ 'is-loading': isLoading, 'disabled': isLoading }">
          <i class="fas fa-sync-alt"></i>
          刷新
        </button>
      </div>
    </div>
    
    <div class="panel-content">
      <div class="list-scroll" ref="scrollRef">
        <div v-for="(item, index) in displayCompanies" 
          :key="`${item.id}-${index}`"
          class="list-item"
          :style="{ '--delay': `${index * 0.1}s` }"
        >
          <div class="company-info">
            <div class="company-name">{{ item.name }}</div>
            <div class="company-meta">
              <span class="warning-tag">
                <i class="fas fa-exclamation-circle"></i>
                {{ item.reason }}
              </span>
              <span class="time">
                <i class="far fa-clock"></i>
                {{ item.time }}
              </span>
            </div>
          </div>
          <div class="punishment">
            <i class="fas fa-ban"></i>
            {{ item.punishment }}
          </div>
          <div class="severity-level" :class="item.severity">
            <i class="fas fa-exclamation-triangle"></i>
            {{ item.severity }}级严重
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<style scoped lang="scss">
.panel-card {
  display: flex;
  flex-direction: column;
  height: 100%;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  padding: 20px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
  
  &.blacklist {
    --theme-color: #1E293B;
    --theme-bg: rgba(30, 41, 59, 0.1);
    
    &::before {
      content: '';
      position: absolute;
      inset: 0;
      background: linear-gradient(
        135deg,
        rgba(239, 68, 68, 0.05),
        transparent 50%,
        rgba(239, 68, 68, 0.05)
      );
      pointer-events: none;
    }
    
    .list-item {
      position: relative;
      overflow: hidden;
      transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
      border: 1px solid rgba(239, 68, 68, 0.1);
      background: rgba(255, 255, 255, 0.03);
      
      &:hover {
        transform: translateY(-2px);
        background: rgba(255, 255, 255, 0.05);
        border-color: rgba(239, 68, 68, 0.2);
        box-shadow: 0 4px 12px rgba(239, 68, 68, 0.1);
        
        .punishment {
          transform: translateY(-1px);
          background: rgba(239, 68, 68, 0.1);
          border-color: rgba(239, 68, 68, 0.2);
          
          i {
            transform: rotate(180deg);
            color: #EF4444;
          }
        }
      }
    }
  }
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-shrink: 0;
  padding: 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  position: relative;
  
  &::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
    height: 1px;
    background: linear-gradient(
      90deg,
      transparent,
      rgba(255, 255, 255, 0.1),
      transparent
    );
  }
  
  .header-title {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 16px;
    font-weight: 600;
    color: #E2E8F0;
    
    .warning-icon {
      color: #EF4444;
      font-size: 16px;
      filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.3));
    }
    
    .total-count {
      display: flex;
      align-items: center;
      gap: 6px;
      font-size: 13px;
      color: #94A3B8;
      margin-left: 12px;
      padding: 6px 12px;
      background: rgba(239, 68, 68, 0.1);
      border: 1px solid rgba(239, 68, 68, 0.2);
      border-radius: 6px;
      transition: all 0.3s ease;
      
      &:hover {
        background: rgba(239, 68, 68, 0.15);
        transform: translateY(-1px);
      }
      
      i {
        font-size: 12px;
        color: #EF4444;
      }
    }
  }
}

.refresh-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.03);
  color: #94A3B8;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  font-size: 13px;
  
  &:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(255, 255, 255, 0.2);
    color: #E2E8F0;
    transform: translateY(-1px);
  }
  
  &.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
  }
  
  &.is-loading {
    position: relative;
    color: transparent;
    
    &::after {
      content: "";
      position: absolute;
      width: 16px;
      height: 16px;
      border: 2px solid transparent;
      border-top-color: #94A3B8;
      border-radius: 50%;
      animation: spin 0.8s linear infinite;
    }
  }
}

.panel-content {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
  height: calc(100% - 60px);
  
  .list-scroll {
    height: 100%;
    overflow-y: auto;
    padding: 4px 8px;
    
    &:hover {
      &::-webkit-scrollbar-thumb {
        background: rgba(239, 68, 68, 0.2);
      }
    }
    
    &::-webkit-scrollbar {
      width: 4px;
    }
    
    &::-webkit-scrollbar-track {
      background: rgba(255, 255, 255, 0.03);
      border-radius: 2px;
    }
    
    &::-webkit-scrollbar-thumb {
      background: rgba(239, 68, 68, 0.1);
      border-radius: 2px;
      transition: background-color 0.3s ease;
      
      &:hover {
        background: rgba(239, 68, 68, 0.2);
      }
    }
  }
}

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 12px 16px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(239, 68, 68, 0.1);
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  position: relative;
  margin-bottom: 10px;
  animation: slideIn 0.3s ease-out forwards;
  gap: 16px;
  
  &:last-child {
    margin-bottom: 0;
  }
  
  &:hover {
    transform: translateX(4px);
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(239, 68, 68, 0.2);
  }
}

.company-info {
  flex: 1;
  min-width: 0;
  margin-right: 16px;
  
  .company-name {
    font-size: 15px;
    font-weight: 500;
    color: #E2E8F0;
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
    display: block;
  }
  
  .company-meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 13px;
    flex-wrap: wrap;
  }
}

.warning-tag {
  padding: 4px 10px;
  border-radius: 6px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: #EF4444;
  position: relative;
  transition: all 0.3s ease;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 120px;
  max-width: 300px;
  display: flex;
  align-items: center;
  
  i {
    margin-right: 6px;
    color: #EF4444;
    flex-shrink: 0;
  }
  
  span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
}

.time {
  color: #94A3B8;
  white-space: nowrap;
  padding: 4px 10px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 6px;
  min-width: 120px;
  display: flex;
  align-items: center;
  
  i {
    color: #64748B;
    margin-right: 6px;
    flex-shrink: 0;
  }
}

.punishment {
  position: relative;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  padding: 6px 14px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid rgba(239, 68, 68, 0.2);
  color: #EF4444;
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 0.5px;
  display: flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 120px;
  max-width: 150px;
  flex-shrink: 0;
  
  i {
    transition: transform 0.3s ease;
    flex-shrink: 0;
  }
}

.severity-level {
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  min-width: 100px;
  text-align: center;
  white-space: nowrap;
  flex-shrink: 0;
  border: 1px solid transparent;
  display: flex;
  align-items: center;
  justify-content: center;
  
  &.high {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.2);
    color: #EF4444;
  }
  
  &.medium {
    background: rgba(245, 158, 11, 0.1);
    border-color: rgba(245, 158, 11, 0.2);
    color: #F59E0B;
  }
  
  &.low {
    background: rgba(59, 130, 246, 0.1);
    border-color: rgba(59, 130, 246, 0.2);
    color: #3B82F6;
  }
  
  i {
    margin-right: 6px;
    font-size: 12px;
    flex-shrink: 0;
  }
}

@keyframes pulse {
  0% { transform: scale(1); filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.3)); }
  50% { transform: scale(1.1); filter: drop-shadow(0 0 12px rgba(239, 68, 68, 0.5)); }
  100% { transform: scale(1); filter: drop-shadow(0 0 8px rgba(239, 68, 68, 0.3)); }
}

.pulse {
  animation: pulse 2s infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1600px) {
  .panel-card {
    padding: 16px;
    border-radius: 14px;
  }
  
  .panel-header {
    padding: 14px;
    margin-bottom: 14px;
  }
  
  .list-item {
    padding: 10px 14px;
    gap: 12px;
  }
  
  .company-info {
    margin-right: 12px;
  }
  
  .warning-tag {
    min-width: 100px;
    max-width: 250px;
  }
  
  .time {
    min-width: 110px;
  }
  
  .punishment {
    min-width: 110px;
    max-width: 140px;
  }
}

@media (max-width: 1366px) {
  .panel-card {
    padding: 14px;
    border-radius: 12px;
  }
  
  .panel-header {
    padding: 12px;
    margin-bottom: 12px;
    
    .header-title {
      font-size: 15px;
      
      .warning-icon {
        font-size: 15px;
      }
      
      .total-count {
        font-size: 12px;
        padding: 4px 10px;
      }
    }
  }
  
  .list-item {
    padding: 8px 12px;
    gap: 8px;
  }
  
  .company-info {
    margin-right: 8px;
    
    .company-name {
      font-size: 14px;
    }
    
    .company-meta {
      font-size: 12px;
    }
  }
  
  .warning-tag {
    min-width: 90px;
    max-width: 200px;
    font-size: 12px;
    padding: 4px 8px;
  }
  
  .time {
    min-width: 100px;
    font-size: 12px;
    padding: 4px 8px;
  }
  
  .punishment {
    min-width: 100px;
    max-width: 130px;
    font-size: 12px;
    padding: 4px 8px;
  }
  
  .severity-level {
    min-width: 90px;
    font-size: 12px;
    padding: 4px 8px;
  }
}
</style>
